import request from '#/utils/requestAbort';
import { SERVER_URL_OBJ } from '@/../config/urlConfig';
// 省份-交易中心-场站（数据权限）
export async function queryMarketList(menuCode) {
  return request(`/power/dataPower/common/${menuCode}/t_station`, {
    method: 'GET',
  });
}
export async function flexibleAggregation(params) {
  const env = CLIENT_ENV === 'dev' ? 'test' : CLIENT_ENV;
  const { stationIdList, dataTimeOrderType, startDate, endDate, dataType, marketId } = params;
  delete params.startDate;
  delete params.endDate;
  delete params.region;
  delete params.stationIdList;
  delete params.dataTimeOrderType;

  let serviceName = 'reanalyze';

  if (marketId === 'PDBLJ') {
    serviceName = 'private-business';
  }
  return request('/generation-common/flexible-aggregation/flexibleAggregation', {
    method: 'POST',
    data: {
      cacheable: true,
      needTotal: true,
      ...params,
      param: JSON.stringify({
        stationIdList,
        dataTimeOrderType,
        startDate,
        endDate,
        reanalyzeDataType: dataType,
      }),
      url: `${SERVER_URL_OBJ[env]}/${serviceName}/provinceSpotAnalysis/provinceSpotReanalyzeData`,
    },
  });
}

// 辽宁、黑龙江查询接口
export async function newFlexibleAggregation(params) {
  const { stationIdList, dataTimeOrderType, startDate, endDate, dataType, region, marketId } =
    params;
  let url = '/reanalyze/provinceSpotAnalysis/v2/provinceSpotReanalyzeData';

  if (region === '23') {
    url = '/private-business/transProvincialSpotReplay/getReanalyzeData';
  }

  return request(`${url}`, {
    method: 'POST',
    data: {
      provinceSpotReanalyzeDataReqBody: {
        stationIdList,
        dataTimeOrderType,
        startDate,
        endDate,
        reanalyzeDataType: dataType,
        marketId,
      },
      flexAggrBody: {
        order: params.order,
        orderSize: 3,
        needTotal: true,
        timeOrder: dataTimeOrderType,
        headType: 1,
      },
    },
  });
}

// 黑龙江查询接口
export async function flexibleAggregationHLJ(params) {
  const { stationIdList, dataTimeOrderType, startDate, endDate, dataType, region } = params;
  return request('/private-business/transProvincialSpotReplay/getReanalyzeData', {
    method: 'POST',
    data: {
      provinceSpotReanalyzeDataReqBody: {
        stationIdList,
        dataTimeOrderType,
        startDate,
        endDate,
        reanalyzeDataType: dataType,
      },
      flexAggrBody: {
        order: params.order,
        orderSize: 3,
        needTotal: true,
        timeOrder: dataTimeOrderType,
        headType: 1,
      },
    },
  });
}
